import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @Author lizelong
 * @ClassName java.DogSayHello
 * @Date 2021/5/26 14:16
 * @Version V1.0
 * Description  <请输入一句话描述该类功能>
 * Copyright (C) 北京中电兴发科技有限公司  since 2021/5/26
 */
public class DogSayHello implements SayHello {
    @Override
    public void sayHello() {
        System.out.println("汪汪汪^_^");
    }

    public <T> void sayGeneric(T e) {
        Class<?> a = e.getClass();
        Method[] methods = a.getDeclaredMethods();
        Arrays.stream(methods).forEach(method -> {
            method.setAccessible(true);
            try {
                method.invoke(a.newInstance());
            } catch (IllegalAccessException illegalAccessException) {
                illegalAccessException.printStackTrace();
            } catch (InvocationTargetException invocationTargetException) {
                invocationTargetException.printStackTrace();
            } catch (InstantiationException instantiationException) {
                instantiationException.printStackTrace();
            }
            method.setAccessible(false);
        });
        for (Method method : methods) {
            method.setAccessible(true);
            try {
                method.invoke(a.newInstance());
            } catch (IllegalAccessException illegalAccessException) {
                illegalAccessException.printStackTrace();
            } catch (InvocationTargetException invocationTargetException) {
                invocationTargetException.printStackTrace();
            } catch (InstantiationException instantiationException) {
                instantiationException.printStackTrace();
            }
            method.setAccessible(false);
        }
    }

}
